package com.ruoyi.project.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.Prizes;
import com.ruoyi.project.system.service.IPrizesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 奖品配置Controller
 * 
 * @author ruoyi
 * @date 2025-06-11
 */
@RestController
@RequestMapping("/data/prizes")
public class PrizesController extends BaseController
{
    @Autowired
    private IPrizesService prizesService;

    /**
     * 查询奖品配置列表
     */
    @PreAuthorize("@ss.hasPermi('data:prizes:list')")
    @GetMapping("/list")
    public TableDataInfo list(Prizes prizes)
    {
        startPage();
        List<Prizes> list = prizesService.selectPrizesList(prizes);
        return getDataTable(list);
    }

    /**
     * 导出奖品配置列表
     */
    @PreAuthorize("@ss.hasPermi('data:prizes:export')")
    @Log(title = "奖品配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Prizes prizes)
    {
        List<Prizes> list = prizesService.selectPrizesList(prizes);
        ExcelUtil<Prizes> util = new ExcelUtil<Prizes>(Prizes.class);
        util.exportExcel(response, list, "奖品配置数据");
    }

    /**
     * 获取奖品配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('data:prizes:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(prizesService.selectPrizesById(id));
    }

    /**
     * 新增奖品配置
     */
    @PreAuthorize("@ss.hasPermi('data:prizes:add')")
    @Log(title = "奖品配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Prizes prizes)
    {
        return toAjax(prizesService.insertPrizes(prizes));
    }

    /**
     * 修改奖品配置
     */
    @PreAuthorize("@ss.hasPermi('data:prizes:edit')")
    @Log(title = "奖品配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Prizes prizes)
    {
        return toAjax(prizesService.updatePrizes(prizes));
    }

    /**
     * 删除奖品配置
     */
    @PreAuthorize("@ss.hasPermi('data:prizes:remove')")
    @Log(title = "奖品配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(prizesService.deletePrizesByIds(ids));
    }
}
